package swd.work.dataview_wizard_detail;

import com.pub.database.*;
import javax.servlet.http.*;
import com.pub.web.*;

public class Action {
   QueryBean gqbnDAO=null;
   public String action(javax.servlet.jsp.PageContext pageContext){
      HttpServletRequest request=(HttpServletRequest)pageContext.getRequest();
      HttpServletResponse response=(HttpServletResponse)pageContext.getResponse();

      View view=(View)request.getAttribute("view");
      (new WebFunction()).setPortal_to_session(request); //set session from portal
      if (request.getSession().getAttribute("u_id")==null) {
         try{
            request.getRequestDispatcher((new StringBuffer("login.jsp")).insert(0,"/").toString()).forward(request,response);
            return "login";
         }
         catch(Exception le){
            view.setOnloadScript("can not redirect to login page...please contact IT");
            return "";
         }
      }
      gqbnDAO=new QueryBean(view.getDBAlias(),view.getDBDebug(),view.getSourceCharset(),view.getTargetCharset());

      Business business=new Business(gqbnDAO);

      String lstrResult=null;

      try{
          if(view.getprg_no()!=null && view.getdataview_seqno()!=null){
              lstrResult = business.selectTableDataToFld(view);
              if(lstrResult!=null && lstrResult==""){
                  //組合SQL語法
                  view.setsql_statement(business.combineSQLStatement(view));
                  //將column list擷取出來
                  lstrResult=business.getColumnsList(view);
                  if(lstrResult!=null && lstrResult!=""){
                      view.setOnloadScript("alert('"+lstrResult+"')");
                  }
              }
          }

      }

      catch(Exception e){
         e.printStackTrace();

      }
      finally{
          try{
             if(gqbnDAO!=null){
                gqbnDAO.close();
             }
          }
          catch(Exception e){
             System.out.println("can not close querybean in Action.java");
          }

      }
      return "";
   }

}
